package MapReduce.ETL;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class etlMapper extends Mapper<LongWritable, Text,Text, NullWritable> {

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {

        // 1 获取一行数据
        String line = value.toString();

        // 3 判断ETL
        boolean result = parseLog(line,context);
        if(!result){
            return;
        }
        // 4 写出
        context.write(value,NullWritable.get());
    }

    private boolean parseLog(String line, Context context) {

        // 切割
        String[] fields = line.split(" ");

        // 判断日志长度是否大于11
        if(fields.length > 21){
            return true;
        }else{
            return false;
        }
    }
}
